<!-- HTML header for doxygen 1.8.13-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>MTB CAT1 Peripheral driver library: TDM/I2S      (Time Division Multiplexing/Inter-IC Sound)</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen_style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><a href="http://www.cypress.com/"><img alt="Logo" src="IFXCYP_one-line.png"/></a></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">MTB CAT1 Peripheral driver library</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('group__group__tdm.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#groups">API Reference</a>  </div>
  <div class="headertitle">
<div class="title">TDM/I2S (Time Division Multiplexing/Inter-IC Sound)</div>  </div>
</div><!--header-->
<div class="contents">
<a name="details" id="details"></a><h2 class="groupheader">General Description</h2>
<dl class="section note"><dt>Note</dt><dd>IP Supported: TDM </dd>
<dd>
Device Categories: CAT1B. Please refer <a href="usergroup1.html">Device Catalog</a>. Configures audio TDM/I2S.</dd></dl>
<p>The functions and other declarations used in this driver are in cy_tdm.h. You can include cy_pdl.h (ModusToolbox only) to get access to all functions and declarations in the PDL.</p>
<p>Features:</p><ul>
<li>Supports I2S mode and TDM mode.</li>
<li>Master and slave functionality.</li>
<li>Full-duplex transmitter and receiver operation.</li>
<li>Support for up to 32 channels.</li>
<li>Programmable channel size (up to 32 bits)</li>
<li>Programmable channel delay of 0 or 1 bit.</li>
<li>Delayed sampling support.</li>
<li>Programmable PCM sample formatting (8, 10, 12, 14, 16, 18, 20, 24, 32 bits).</li>
<li>Programmable synchronization pulse type.</li>
<li>Left-aligned and right-aligned sample formatting.</li>
<li>128 entry TX FIFO with interrupt and trigger support.</li>
<li>128 entry RX FIFO with interrupt and trigger support.</li>
</ul>
<h1><a class="anchor" id="group_tdm_configuration"></a>
Configuration Considerations</h1>
<p>To set up a TDM driver, initialize the TDM Transmitter module in accordance with a configuration structure.</p>
<ul>
<li>Each TDM/I2S (TX, RX) pair consists of a TDM/I2S transmitter and a TDM/I2S receiver.</li>
<li>The transmitter and receiver can function simultaneously and have dedicated clock control.</li>
<li>The transmitter and receiver have dedicated MMIO registers and a dedicated FIFO.</li>
<li>The transmitter and receiver have a dedicated FIFO interrupt and FIFO trigger.</li>
<li>The transmitter trigger is activated when a programmable number of PCM data slots is available in the TX FIFO.</li>
<li>The receiver trigger is activated when a programmable number of PCM data words is received into the RX FIFO.</li>
</ul>
<p>To set up TDM, provide the configuration parameters in the <a class="el" href="structcy__stc__tdm__config__t.html">cy_stc_tdm_config_t</a> structure.</p>
<p>For example, for Tx configuration, set txEnabled to true, configure txDmaTrigger (depending on whether DMA is going to be used or not), set extClk (if an external clock is used), provide clkDiv, masterMode, sckPolarity, fsyncPolarity, channelSize, wordSize, either i2sMode or TDM (based on Mode setting), fifoTriggerLevel (when the Trig interrupt will be used) and format A similar setup is for the Rx configuration.</p>
<p>To initialize the TDM block, call the <a class="el" href="group__group__tdm__functions.html#gae7bc5f95243b5aa4398ab3935ff15e3f">Cy_AudioTDM_Init</a> function, providing the filled <a class="el" href="structcy__stc__tdm__config__t.html">cy_stc_tdm_config_t</a> structure. Before starting the transmission, enable the Tx <a class="el" href="group__group__tdm__functions.html#ga96f70d0e8eb752eebf31ce77d4ad2632">Cy_AudioTDM_EnableTx</a>, then fill the first Tx data frame by calling <a class="el" href="group__group__tdm__functions.html#ga707bfbd30f94367d0bdefc6967bdf698">Cy_AudioTDM_WriteTxData</a>. Then call the <a class="el" href="group__group__tdm__functions.html#ga9a7179ac79cf588bc83c50b493b2e4c3">Cy_AudioTDM_ActivateTx</a>. For the reception the sequence is the same except for filling the first data frame.</p>
<p>For example: </p><div class="fragment"><div class="line">    <span class="comment">/* Scenario: Setup a duplex 16-bit TDM interface */</span></div><div class="line">    </div><div class="line">    <a class="code" href="structcy__stc__tdm__config__tx__t.html">cy_stc_tdm_config_tx_t</a> tdm_lpbk_tx_config = </div><div class="line">    {</div><div class="line">        .<a class="code" href="structcy__stc__tdm__config__tx__t.html#a3bc0d8a5a0059e0012490022c3f06a3d">enable</a> = <span class="keyword">true</span>,</div><div class="line">        .masterMode = <a class="code" href="group__group__tdm__enums.html#ggacf788712265d4ce0fdbf0b9aed4bb38fa3ca5d1469b5a17cf9c78cdbb67b67f85">CY_TDM_DEVICE_MASTER</a>,</div><div class="line">        .wordSize = <a class="code" href="group__group__tdm__enums.html#gga3e7c9522bd7a7e179487ac26fcec0129ae65efb9a138a9e9f092171ccb3f74a03">CY_TDM_SIZE_16</a>,</div><div class="line">        .format = <a class="code" href="group__group__tdm__enums.html#gga17c76544100c74ac3f72bd1a23131acfac182e064197e820b299f1463cfcbb1ff">CY_TDM_LEFT</a>,</div><div class="line">        .clkDiv = 16,</div><div class="line">        .clkSel = <a class="code" href="group__group__tdm__enums.html#gga6e68e27138e141adeaca8402fd032e37a2bd01fe401f54f9137bf7508498ba68f">CY_TDM_SEL_SRSS_CLK0</a>,</div><div class="line">        .sckPolarity = <a class="code" href="group__group__tdm__enums.html#gga740465810e855730300bda1ca68a3f29a4e404e5113b0a22b27b38f8aaa11365b">CY_TDM_CLK</a>,</div><div class="line">        .fsyncPolarity = <a class="code" href="group__group__tdm__enums.html#ggae049ad85366a084a1bbf3ef69109c0c5a6570d2bb402a9ebb76a64b8e15e23c56">CY_TDM_SIGN</a>,</div><div class="line">        .fsyncFormat = <a class="code" href="group__group__tdm__enums.html#gga0beaff668ba6388ecccaf62524a37449a044ff60ba2cb87dc7c5d13d9519435f7">CY_TDM_CH_PERIOD</a>,</div><div class="line">        .channelNum = 2,</div><div class="line">        .channelSize = 16,</div><div class="line">        .fifoTriggerLevel = 36,</div><div class="line">        .chEn = 0x3,</div><div class="line">        .signalInput = 0,</div><div class="line">        .i2sMode = <span class="keyword">true</span>,</div><div class="line">    };</div><div class="line">    <a class="code" href="structcy__stc__tdm__config__rx__t.html">cy_stc_tdm_config_rx_t</a> tdm_lpbk_rx_config = </div><div class="line">    {</div><div class="line">        .<a class="code" href="structcy__stc__tdm__config__rx__t.html#a4a4839e77c81bf1fe7c32b8edf67befe">enable</a> = <span class="keyword">true</span>,</div><div class="line">        .masterMode = <a class="code" href="group__group__tdm__enums.html#ggacf788712265d4ce0fdbf0b9aed4bb38faf0bd0ae5bf302ab477c1a51fc00e94c7">CY_TDM_DEVICE_SLAVE</a>,</div><div class="line">        .wordSize = <a class="code" href="group__group__tdm__enums.html#gga3e7c9522bd7a7e179487ac26fcec0129ae65efb9a138a9e9f092171ccb3f74a03">CY_TDM_SIZE_16</a>,</div><div class="line">        .signExtend = <a class="code" href="group__group__tdm__enums.html#ggab0793a864efd973075babaea02b09fe2ac7f26d49bed3f38b0e2d1a8ab767a89a">CY_ZERO_EXTEND</a>,</div><div class="line">        .format = <a class="code" href="group__group__tdm__enums.html#gga17c76544100c74ac3f72bd1a23131acfac182e064197e820b299f1463cfcbb1ff">CY_TDM_LEFT</a>,</div><div class="line">        .clkDiv = 16,</div><div class="line">        .clkSel = <a class="code" href="group__group__tdm__enums.html#gga6e68e27138e141adeaca8402fd032e37a2bd01fe401f54f9137bf7508498ba68f">CY_TDM_SEL_SRSS_CLK0</a>,</div><div class="line">        .sckPolarity = <a class="code" href="group__group__tdm__enums.html#gga740465810e855730300bda1ca68a3f29a4e404e5113b0a22b27b38f8aaa11365b">CY_TDM_CLK</a>,</div><div class="line">        .fsyncPolarity = <a class="code" href="group__group__tdm__enums.html#ggae049ad85366a084a1bbf3ef69109c0c5a6570d2bb402a9ebb76a64b8e15e23c56">CY_TDM_SIGN</a>,</div><div class="line">        .lateSample = <span class="keyword">false</span>,</div><div class="line">        .fsyncFormat = <a class="code" href="group__group__tdm__enums.html#gga0beaff668ba6388ecccaf62524a37449a044ff60ba2cb87dc7c5d13d9519435f7">CY_TDM_CH_PERIOD</a>,</div><div class="line">        .channelNum = 2,</div><div class="line">        .channelSize = 16,</div><div class="line">        .fifoTriggerLevel = 32,</div><div class="line">        .chEn = 0x3,</div><div class="line">        .signalInput = 0,</div><div class="line">        .i2sMode = <span class="keyword">true</span>,</div><div class="line">    };</div><div class="line">    <span class="keyword">const</span> <a class="code" href="structcy__stc__tdm__config__t.html">cy_stc_tdm_config_t</a> tdm_lpbk_config = </div><div class="line">    {</div><div class="line">        .<a class="code" href="structcy__stc__tdm__config__t.html#a5124d3ceb59c78480f465a6f6f76575f">tx_config</a> = &amp;tdm_lpbk_tx_config,</div><div class="line">        .rx_config = &amp;tdm_lpbk_rx_config,</div><div class="line">    };</div><div class="line">    </div><div class="line">    <span class="keywordflow">if</span>(<a class="code" href="group__group__tdm__enums.html#gga4d3b2e281577620b2eaf8fa3a75b05feab1f24a349d2360e36de4c178efe2bd54">CY_TDM_SUCCESS</a> != <a class="code" href="group__group__tdm__functions.html#gae7bc5f95243b5aa4398ab3935ff15e3f">Cy_AudioTDM_Init</a>(TDM_STRUCT0, &amp;tdm_lpbk_config))</div><div class="line">    {</div><div class="line">        <span class="comment">/* Insert error handling */</span></div><div class="line">    }</div><div class="line">   </div><div class="line">    <span class="comment">/* Clear possible pending interrupts */</span></div><div class="line">    <a class="code" href="group__group__tdm__functions.html#ga7ad88fce4918a1304f54c6830e222241">Cy_AudioTDM_ClearTxInterrupt</a>(TDM_STRUCT0_TX, CY_TDM_INTR_TX_MASK);</div><div class="line">    <a class="code" href="group__group__tdm__functions.html#ga328d82b1e5f578b773269767f2bee564">Cy_AudioTDM_ClearRxInterrupt</a>(TDM_STRUCT0_RX, CY_TDM_INTR_RX_MASK);</div><div class="line">    <span class="comment">/* Enable interrupts */</span></div><div class="line">    <a class="code" href="group__group__tdm__functions.html#ga728172f4cfb1c1c4cf58a8179c501394">Cy_AudioTDM_SetTxInterruptMask</a>(TDM_STRUCT0_TX, CY_TDM_INTR_TX_MASK);</div><div class="line">    <a class="code" href="group__group__tdm__functions.html#ga44fe61f227646b347344860a7eb63074">Cy_AudioTDM_SetRxInterruptMask</a>(TDM_STRUCT0_RX, CY_TDM_INTR_RX_MASK);</div><div class="line">    <span class="comment">/* Enable the TDM interface */</span></div><div class="line">    <a class="code" href="group__group__tdm__functions.html#gadb6bb66c4efb11254ae62aaee183d83a">Cy_AudioTDM_EnableRx</a>(TDM_STRUCT0_RX);</div><div class="line">    <a class="code" href="group__group__tdm__functions.html#ga96f70d0e8eb752eebf31ce77d4ad2632">Cy_AudioTDM_EnableTx</a>(TDM_STRUCT0_TX);</div></div><!-- fragment --><p> If you use a DMA, the DMA channel should be previously configured. The TDM interrupts (if applicable) can be enabled by calling <a class="el" href="group__group__tdm__functions.html#ga728172f4cfb1c1c4cf58a8179c501394">Cy_AudioTDM_SetTxInterruptMask</a>.</p>
<p>For example, if the trigger interrupt is used during operation, the ISR should call the <a class="el" href="group__group__tdm__functions.html#ga707bfbd30f94367d0bdefc6967bdf698">Cy_AudioTDM_WriteTxData</a> as many times as required for your FIFO payload, but not more than the FIFO size. Then call <a class="el" href="group__group__tdm__functions.html#ga7ad88fce4918a1304f54c6830e222241">Cy_AudioTDM_ClearTxInterrupt</a> with appropriate parameters.</p>
<p>If a DMA is used and the DMA channel is properly configured - no CPU activity (or any application code) is needed for I2S/TDM operation.</p>
<p>The I2S frame appears as: </p><div class="image">
<img src="i2s_frame.png" alt="i2s_frame.png"/>
</div>
<p> This is an example for the channel length = 32. A similar case exists for the rest channel length configuration, with one limitation: the word length should be less than or equal to the channel length. See the datasheet of your device for more details.</p>
<h1><a class="anchor" id="group_tdm_MISRA"></a>
MISRA-C Compliance</h1>
<p>The TDM driver has the following specific deviations:</p>
<table class="doxtable">
<tr>
<th>MISRA Rule </th><th>Rule Class (Required/Advisory) </th><th>Rule Description </th><th>Description of Deviation(s)  </th></tr>
<tr>
<td>10.3 </td><td>R </td><td>A composite expression of the "essentially unsigned" type is being cast to a different type category. </td><td>The value got from the bitfield physically cannot exceed the enumeration that describes this bitfield. So, the code is safe by design.  </td></tr>
<tr>
<td>11.4 </td><td>A </td><td>A cast should not be performed between a pointer to object type and a different pointer to object type. </td><td></td></tr>
<tr>
<td>20.3 </td><td>R </td><td>The validity of values passed to library functions shall be checked. </td><td>This violation is not caused by code changes, i.e. is not a regression.  </td></tr>
</table>
<h1><a class="anchor" id="group_tdm_changelog"></a>
Changelog</h1>
<table class="doxtable">
<tr>
<th>Version</th><th>Changes</th><th>Reason for Change </th></tr>
<tr>
<td>1.0 </td><td>Initial version </td><td></td></tr>
</table>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="groups"></a>
API Reference</h2></td></tr>
<tr class="memitem:group__group__tdm__i2s__macros__interrupt__masks"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__tdm__i2s__macros__interrupt__masks.html">Interrupt Masks</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:group__group__tdm__data__structures"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__tdm__data__structures.html">Data Structures</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:group__group__tdm__enums"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__tdm__enums.html">Enumerated Types</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:group__group__tdm__macros"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__tdm__macros.html">Macros</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:group__group__tdm__functions"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__tdm__functions.html">Functions</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part
<div id="nav-path" class="navpath">
    <ul>
        <li class="footer">
            Generated for <b>MTB CAT1 Peripheral driver library</b> by <b>Cypress Semiconductor Corporation</b>.
            All rights reserved.
        </li>
    </ul>
</div>
-->
</body>
</html>
